#include "StdAfx.h"
#include "Garuda.h"

Garuda::Garuda()
{
}

Garuda::~Garuda()
{
}

void Garuda::go()
{
#ifdef _DEBUG
	resourcesCfg = "resources_d.cfg";
	pluginsCfg = "plugins_d.cfg";
#else
	resourcesCfg = "resources.cfg";
	pluginsCfg = "plugins.cfg";
#endif

	if (setup())
		root->startRendering();

	// clean up
	destroyScene();
}

bool Garuda::setup(void)
{
	root = new Ogre::Root(pluginsCfg);

	setupResources();

	if (!configure())
		return false;

	chooseSceneManager();
	createViewports();

	// Set default mipmap level (NB some APIs ignore this)
	Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);

	// Create any resource listeners (for loading screens)
	createResourceListener();

	// Load resources
	loadResources();

	// Create the scene
	createScene();

	createFrameListener();

	return true;
}

void Garuda::setupResources(void)
{
	// Load resource paths from config file
	Ogre::ConfigFile cf;
	cf.load(resourcesCfg);

	// Go through all sections & settings in the file
	Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();

	Ogre::String secName, typeName, archName;
	Ogre::ResourceGroupManager rgm = Ogre::ResourceGroupManager::getSingleton();
	Ogre::ConfigFile::SettingsMultiMap *settings;
	Ogre::ConfigFile::SettingsMultiMap::iterator i;

	while (seci.hasMoreElements())
	{
		secName = seci.peekNextKey();
		settings = seci.getNext();

		for (i = settings->begin(); i != settings->end(); ++i)
		{
			typeName = i->first;
			archName = i->second;
			rgm.addResourceLocation(archName, typeName, secName);
		}
	}
}

bool Garuda::configure(void)
{
	// Show the configuration dialog and initialise the system
	// You can skip this and use root.restoreConfig() to load configuration
	// settings if you were sure there are valid ones saved in ogre.cfg
	if(root->showConfigDialog())
	{
		// If returned true, user clicked OK so initialise
		// Here we choose to let the system create a default rendering window by passing 'true'
		window = root->initialise(true, "Garuda");

		return true;
	}
	else
	{
		return false;
	}
}

void Garuda::chooseSceneManager(void)
{
	sceneMgr = root->createSceneManager(Ogre::ST_EXTERIOR_REAL_FAR);
}

void Garuda::createViewports(void)
{
}

void Garuda::createResourceListener(void)
{
}

void Garuda::loadResources(void)
{
}

void Garuda::createScene(void)
{
}

void Garuda::createFrameListener(void)
{
}

void Garuda::configureTerrainDefaults(Ogre::Light* light)
{
}

void Garuda::defineTerrain(long x, long y)
{
}

void Garuda::initBlendMaps(Ogre::Terrain* terrain)
{
}

void Garuda::getTerrainImage(bool flipX, bool flipY, Ogre::Image& img)
{
}

bool Garuda::frameRenderingQueued(const Ogre::FrameEvent& evt)
{
	return false;
}

bool Garuda::keyPressed(const OIS::KeyEvent &arg)
{
	return true;
}

bool Garuda::keyReleased(const OIS::KeyEvent &arg)
{
	return false;
}

bool Garuda::mouseMoved(const OIS::MouseEvent &arg)
{
	return false;
}

bool Garuda::mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
{
	return false;
}

bool Garuda::mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
{
	return false;
}

void Garuda::windowResized(Ogre::RenderWindow* rw)
{
}

void Garuda::windowClosed(Ogre::RenderWindow* rw)
{
}

void Garuda::destroyScene(void)
{
}